home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '87 / Source ƒ.sea / Source ƒ / emacs source ƒ / VMSVT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-28  |  6.3 KB  |  336 lines  |  [TEXT/MARC]

  1. /*
  2.  *  VMS terminal handling routines
  3.  *
  4.  *  Known types are:
  5.  *    VT52, VT100, and UNKNOWN (which is defined to be an ADM3a)
  6.  *    written by Curtis Smith
  7.  */
  8.  
  9. #include        <stdio.h>
  10. #include        "estruct.h"
  11. #include    "edef.h"
  12.  
  13. #if     VMSVT
  14.  
  15. #define    termdef    1            /* don't define "term" external */
  16.  
  17. #include <ssdef.h>        /* Status code definitions        */
  18. #include <descrip.h>        /* Descriptor structures        */
  19. #include <iodef.h>        /* IO commands                */
  20. #include <ttdef.h>        /* tty commands                */
  21.  
  22. extern  int     ttopen();               /* Forward references.          */
  23. extern  int     ttgetc();
  24. extern  int     ttputc();
  25. extern  int     ttflush();
  26. extern  int     ttclose();
  27. extern  int    vmsopen();
  28. extern    int    vmskopen();
  29. extern    int    vmskclose();
  30. extern  int    vmseeol();
  31. extern  int    vmseeop();
  32. extern  int    vmsbeep();
  33. extern  int    vmsmove();
  34. extern    int    vmsrev();
  35. extern  int    eolexist;
  36. #if    COLOR
  37. extern    int    vmsfcol();
  38. extern    int    vmsbcol();
  39. #endif
  40.  
  41. #define    NROWS    24            /* # of screen rolls        */
  42. #define    NCOLS    80            /* # of screen columns        */
  43. #define    MARGIN    8            /* size of minimim margin and    */
  44. #define    SCRSIZ    64            /* scroll size for extended lines */
  45. #define    NPAUSE    100            /* # times thru update to pause */
  46.  
  47. /*
  48.  * Dispatch table. All the
  49.  * hard fields just point into the
  50.  * terminal I/O code.
  51.  */
  52. TERM    term    = {
  53.     NROWS - 1,
  54.     NCOLS,
  55.     MARGIN,
  56.     SCRSIZ,
  57.     NPAUSE,
  58.         &vmsopen,
  59.         &ttclose,
  60.     &vmskopen,
  61.     &vmskclose,
  62.         &ttgetc,
  63.         &ttputc,
  64.         &ttflush,
  65.         &vmsmove,
  66.         &vmseeol,
  67.         &vmseeop,
  68.         &vmsbeep,
  69.         &vmsrev
  70. #if    COLOR
  71.     , &vmsfcol,
  72.     &vmsbcol
  73. #endif
  74. };
  75.  
  76. char * termeop;            /* Erase to end of page string        */
  77. int eoppad;            /* Number of pad characters after eop    */
  78. char * termeol;            /* Erase to end of line string        */
  79. int eolpad;            /* Number of pad characters after eol    */
  80. char termtype;            /* Terminal type identifier        */
  81.  
  82.  
  83. /*******
  84.  *  ttputs - Send a string to ttputc
  85.  *******/
  86.  
  87. ttputs(string)
  88. char * string;
  89. {
  90.     while (*string != '\0')
  91.         ttputc(*string++);
  92. }
  93.  
  94.  
  95. /*******
  96.  *  vmspad - Pad the output after an escape sequence
  97.  *******/
  98.  
  99. vmspad(count)
  100. int count;
  101. {
  102.     while (count-- > 0)
  103.         ttputc('\0');
  104. }
  105.  
  106.  
  107. /*******
  108.  *  vmsmove - Move the cursor
  109.  *******/
  110.  
  111. vmsmove(row, col)
  112. {
  113.     switch (termtype) {
  114.         case TT$_UNKNOWN:
  115.             ttputc('\033');
  116.             ttputc('=');
  117.             ttputc(row+' ');
  118.             ttputc(col+' ');
  119.             break;
  120.         case TT$_VT52:
  121.             ttputc('\033');
  122.             ttputc('Y');
  123.             ttputc(row+' ');
  124.             ttputc(col+' ');
  125.             break;
  126.                 case TT$_VT100:         /* I'm assuming that all these  */
  127.                 case TT$_VT101:         /* are a super set of the VT100 */
  128.                 case TT$_VT102:         /* If I'm wrong, just remove    */
  129.                 case TT$_VT105:         /* those entries that aren't.   */
  130.                 case TT$_VT125:
  131.                 case TT$_VT131:
  132.                 case TT$_VT132:
  133.                 case TT$_VT200_SERIES:
  134.             {
  135.                 char buffer[24];
  136.  
  137.                 sprintf(buffer, "\033[%d;%dH", row+1, col+1);
  138.                 ttputs(buffer);
  139.                 vmspad(50);
  140.             }
  141.     }
  142. }
  143.  
  144. /*******
  145.  *  vmsrev - set the reverse video status
  146.  *******/
  147.  
  148. vmsrev(status)
  149.  
  150. int status;    /* TRUE = reverse video, FALSE = normal video */
  151. {
  152.     switch (termtype) {
  153.         case TT$_UNKNOWN:
  154.             break;
  155.         case TT$_VT52:
  156.             break;
  157.         case TT$_VT100:
  158.             if (status) {
  159.                 ttputc('\033');
  160.                 ttputc('[');
  161.                 ttputc('7');
  162.                 ttputc('m');
  163.             } else {
  164.                 ttputc('\033');
  165.                 ttputc('[');
  166.                 ttputc('m');
  167.             }
  168.             break;
  169.     }
  170. }
  171.  
  172. #if    COLOR
  173. /*******
  174.  *  vmsfcol - Set the forground color (not implimented)
  175.  *******/
  176.  
  177. vmsfcol()
  178. {
  179. }
  180.  
  181. /*******
  182.  *  vmsbcol - Set the background color (not implimented)
  183.  *******/
  184.  
  185. vmsbcol()
  186. {
  187. }
  188. #endif
  189.  
  190. /*******
  191.  *  vmseeol - Erase to end of line
  192.  *******/
  193.  
  194. vmseeol()
  195. {
  196.     ttputs(termeol);
  197.     vmspad(eolpad);
  198. }
  199.  
  200.  
  201. /*******
  202.  *  vmseeop - Erase to end of page (clear screen)
  203.  *******/
  204.  
  205. vmseeop()
  206. {
  207.     ttputs(termeop);
  208.     vmspad(eoppad);
  209. }
  210.  
  211.  
  212. /*******
  213.  *  vmsbeep - Ring the bell
  214.  *******/
  215.  
  216. vmsbeep()
  217. {
  218.     ttputc('\007');
  219. }
  220.  
  221.  
  222. /*******
  223.  *  vmsopen - Get terminal type and open terminal
  224.  *******/
  225.  
  226. vmsopen()
  227. {
  228.     termtype = vmsgtty();
  229.     switch (termtype) {
  230.         case TT$_UNKNOWN:    /* Assume ADM3a    */
  231.             eolexist = FALSE;
  232.             termeop = "\032";
  233.             eoppad = 0;
  234.             break;
  235.         case TT$_VT52:
  236.             termeol = "\033K";
  237.             eolpad = 0;
  238.             termeop = "\033H\033J";
  239.             eoppad = 0;
  240.             break;
  241.         case TT$_VT100:
  242.             revexist = TRUE;
  243.             termeol = "\033[K";
  244.             eolpad = 3;
  245.             termeop = "\033[;H\033[2J";
  246.             eoppad = 50;
  247.             break;
  248.         default:
  249.             puts("Terminal type not supported");
  250.             exit (SS$_NORMAL);
  251.     }
  252.         ttopen();
  253. }
  254.  
  255.  
  256. struct iosb {            /* I/O status block            */
  257.     short    i_cond;        /* Condition value            */
  258.     short    i_xfer;        /* Transfer count            */
  259.     long    i_info;        /* Device information            */
  260. };
  261.  
  262. struct termchar {        /* Terminal characteristics        */
  263.     char    t_class;    /* Terminal class            */
  264.     char    t_type;        /* Terminal type            */
  265.     short    t_width;    /* Terminal width in characters        */
  266.     long    t_mandl;    /* Terminal's mode and length        */
  267.     long    t_extend;    /* Extended terminal characteristics    */
  268. };
  269.  
  270. /*******
  271.  *  vmsgtty - Get terminal type from system control block
  272.  *******/
  273.  
  274. vmsgtty()
  275. {
  276.     short fd;
  277.     int status;
  278.     struct iosb iostatus;
  279.     struct termchar tc;
  280.     $DESCRIPTOR(devnam, "SYS$INPUT");
  281.  
  282.     status = sys$assign(&devnam, &fd, 0, 0);
  283.     if (status != SS$_NORMAL)
  284.         exit (status);
  285.  
  286.     status = sys$qiow(        /* Queue and wait        */
  287.         0,            /* Wait on event flag zero    */
  288.         fd,            /* Channel to input terminal    */
  289.         IO$_SENSEMODE,        /* Get current characteristic    */
  290.         &iostatus,        /* Status after operation    */
  291.         0, 0,            /* No AST service        */
  292.         &tc,            /* Terminal characteristics buf    */
  293.         sizeof(tc),        /* Size of the buffer        */
  294.         0, 0, 0, 0);        /* P3-P6 unused            */
  295.  
  296.                     /* De-assign the input device    */
  297.     if (sys$dassgn(fd) != SS$_NORMAL)
  298.         exit(status);
  299.  
  300.     if (status != SS$_NORMAL)    /* Jump out if bad status    */
  301.         exit(status);
  302.     if (iostatus.i_cond != SS$_NORMAL)
  303.         exit(iostatus.i_cond);
  304.  
  305.     return tc.t_type;        /* Return terminal type        */
  306. }
  307.  
  308. vmskopen()
  309.  
  310. {
  311. }
  312.  
  313. vmskclose()
  314.  
  315. {
  316. }
  317.  
  318. #if    FLABEL
  319. fnclabel(f, n)        /* label a function key */
  320.  
  321. int f,n;    /* default flag, numeric argument [unused] */
  322.  
  323. {
  324.     /* on machines with no function keys...don't bother */
  325.     return(TRUE);
  326. }
  327. #endif
  328. #else
  329.  
  330. hellovms()
  331.  
  332. {
  333. }
  334.  
  335. #endif    VMSVT
  336.